<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button name="btn1">btn1</button>
    <button name="btn2">btn2</button>
    <button name="btn3">btn3</button>
    <button name="btn4">btn4</button>
    <button name="btn5">btn5</button>
    <button name="btn6">btn6</button>

    <script>
    const el = document.querySelectorAll('button')    
    el.forEach(e => {
        const name = e.getAttribute('name')
        e.addEventListener('click', function() {
            console.log(name);
        })
        e = null; // 解决内存泄露
    })
    </script>
</body>
</html>